package myzd.api.controllers;

import io.swagger.annotations.ApiOperation;
import libedge.domain.exceptions.GenericException;
import libedge.domain.request.ResultWrapper;
import myzd.client.domain.LoginTokenResponse;
import myzd.services.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author zks
 * @since 2017/10/18 17:54
 */
@RestController
public class UserController {
  @Value("${sso.authorize}")
  private String ssoLoginHost;
  @Autowired
  private UserService userService;

  @GetMapping(path = "api/v1/login")
  @ApiOperation(value = "返回登录地址", produces = "application/json")
  public ResultWrapper<LoginTokenResponse> getLoginAddress(HttpServletRequest request
  ) throws GenericException {
    String url = request.getScheme() + "://" + request.getHeader("host");
    return new ResultWrapper<>(userService.userSsoLogin(this.ssoLoginHost, url));
  }
}
